package com.sfac.hqyj.springBoot.modules.account.controller;

import com.sfac.hqyj.springBoot.modules.account.service.UserService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Description AccountController
 * @Author HymanHu
 * @Date 2021/4/22 9:40
 */
@Controller
public class AccountController {

    @Autowired
    private UserService userService;
    /**
     * 127.0.0.1/login ---- get
     */
    @GetMapping("/login")
    public String loginPage(ModelMap modelMap) {
        modelMap.addAttribute("template", "account/login");
        return "indexSimple";
    }

    /**
     * 127.0.0.1/logout ---- get
     */
    @GetMapping("/logout")
    public String logout() {
        userService.logout();
        return "redirect:/login";
    }

    /**
     * 127.0.0.1/register ---- get
     */
    @GetMapping("/register")
    public String registerPage(ModelMap modelMap) {
        modelMap.addAttribute("template", "account/register");
        return "indexSimple";
    }

    /**
     * 127.0.0.1/account/users ---- get
     */
    @GetMapping("/account/users")
    @RequiresRoles(value={"admin", "manager"}, logical= Logical.OR)
    public String usersPage() {
        return "index";
    }

    /**
     * 127.0.0.1/account/roles ---- get
     */
    @GetMapping("/account/roles")
    @RequiresRoles(value={"admin", "manager"}, logical= Logical.OR)
    public String rolesPage() {
        return "index";
    }

    /**
     * 127.0.0.1/account/resources ---- get
     */
    @GetMapping("/account/resources")
    @RequiresRoles(value={"admin", "manager"}, logical= Logical.OR)
    public String resourcesPage() {
        return "index";
    }

    /**
     * 127.0.0.1/account/profile ---- get
     */
    @GetMapping("/account/profile")
    public String profilePage(ModelMap modelMap) {
        return "index";
    }
}
